package com.fwzc.giuseppe.adapter;

import java.util.List;

import com.fwzc.giuseppe.util.ViewHolder;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/**
 * 通用的ListView适配器
 * @author llf
 *
 * @param <T>
 */
public abstract class UniversalAdapter<T> extends BaseAdapter{
	private Context context;
	private List<T> datas;
	private int layoutId;
	
	public UniversalAdapter(Context context,List<T> datas,int layoutId){
		this.context = context;
		this.datas = datas;
		this.layoutId = layoutId;
	}
	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public T getItem(int position) {
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = ViewHolder.get(context, convertView, parent, layoutId);
		convert(viewHolder, getItem(position));
		return viewHolder.getConvertView();
	}

	public abstract void convert(ViewHolder viewHolder,T item);
}
